// 存放医生相关的数据
export default {
    //开启命名空间，解决不同模块之间成员冲突的问题
    namespaced: true,
    state: {
        //医生信息
        doctors: [
            { doctorID: '1001', name: "叶天士", department: '儿科', title: '主任医师', phone: '13200001232' },
            { doctorID: '1002', name: "张红梅", department: '内科', title: '副主任医师', phone: '15800004567' },
            { doctorID: '1003', name: "李文博", department: '外科', title: '主治医师', phone: '13900007890' },
            { doctorID: '1004', name: "王丽娟", department: '妇产科', title: '主任医师', phone: '15200002345' },
            { doctorID: '1005', name: "赵晓明", department: '儿科', title: '副主任医师', phone: '13700006789' },
            { doctorID: '1006', name: "陈静", department: '内科', title: '主治医师', phone: '13300003456' },
            { doctorID: '1007', name: "刘强", department: '外科', title: '副主任医师', phone: '15500008901' },
            { doctorID: '1008', name: "孙耳艳", department: '妇产科', title: '主治医师', phone: '13400005678' },
            { doctorID: '1009', name: "李雷", department: '儿科', title: '主任医师', phone: '13800009012' },
            { doctorID: '1010', name: "周子丽", department: '内科', title: '副主任医师', phone: '15600002468' },
            { doctorID: '1011', name: "吴刚", department: '外科', title: '主治医师', phone: '13100003579' },
            { doctorID: '1012', name: "朱小红", department: '妇产科', title: '主任医师', phone: '15900004680' },
            { doctorID: '1013', name: "张伟", department: '儿科', title: '副主任医师', phone: '13600005791' },
            { doctorID: '1014', name: "杨芳", department: '内科', title: '主治医师', phone: '13500006892' },
            { doctorID: '1015', name: "陈达浩", department: '外科', title: '副主任医师', phone: '15700007903' },
            { doctorID: '1016', name: "林娜", department: '妇产科', title: '主治医师', phone: '13000008014' },
            { doctorID: '1017', name: "高勇", department: '儿科', title: '副主任医师', phone: '14200009123' },
            { doctorID: '1018', name: "何阿洁", department: '内科', title: '主治医师', phone: '14500003456' },
            { doctorID: '1019', name: "郑智", department: '外科', title: '主任医师', phone: '14800007890' },
            { doctorID: '1020', name: "孔丽", department: '妇产科', title: '副主任医师', phone: '15100002345' }
        ],
    },
    getters: {

        //计算医生数量
        getDoctorsCount(state) {
            return state.doctors.length;
        }

    },
    mutations: {

        // 添加医生数据
        ADD_NEW_DOCTOR(state, newDoctor) {
            // 直接将新医生添加到 state 中的 doctors 数组
            state.doctors.push(newDoctor);
        },

        // 删除医生数据
        EDIT_DOCTOR(state, updatedDoctor) {
            const index = state.doctors.findIndex(doctor => doctor.doctorID === updatedDoctor.doctorID);
            if (index !== -1) {
                state.doctors.splice(index, 1, updatedDoctor); // 替换原有医生信息
            }
        },

        // 新增 DELETE_DOCTOR mutation
        DELETE_DOCTOR(state, doctorID) {
            const index = state.doctors.findIndex(doctor => doctor.doctorID === doctorID);
            if (index !== -1) {
                state.doctors.splice(index, 1);
            }
        },
    },

    actions: {

        // 简化的 addNewDoctor action，直接调用 mutation 添加医生信息
        addNewDoctor({ commit }, newDoctor) {
            commit('ADD_NEW_DOCTOR', newDoctor);
        },

        //编辑信息
        editDoctor({ commit }, updatedDoctor) {
            commit('EDIT_DOCTOR', updatedDoctor);
        },

        // 新增 deleteDoctor action
        deleteDoctor({ commit }, doctorID) {
            commit('DELETE_DOCTOR', doctorID);
        },
    },

    modules: {
    }
}